<?php

namespace api\channel\taobao;

use api\channel\JdUnion\Base;
use api\channel\jutuike\Union;
use Carbon\Carbon;
use Dml\EasyTBK\Factory;
use easyTbk\taobao\request\EleOrderGetRequest;

class EleOrderChannel extends Union
{

    const APPKEY = 34500897;

    const SECRET = '81de8f2797934fb2adbb1abbbf8cb757';


    const ACTIVITY_ID = '10144';


    const PID = 'alsc_18239032_4439140_12935058';


    //虽然是走淘宝联盟的，因为贪方便，所以随便写个饿了么
    //初始化
    public function __construct()
    {
        parent::__construct(PRODUCT_ELE_SERV); //饿了么
    }

    /**
     *
     * @param $params
     * @return mixed|void
     */
    public function orders($params)
    {
//        优化:同一个秘钥同一个page同一个url就加缓存咯，这样也就是拉一次的效果) https://inews.gtimg.com/newsapp_ls/0/14879756870/0.jiketuchuang.png
        $page = $params['page']??1;

        $taobao = Factory::taobao([
            'app_key' => self::APPKEY,
            'app_secret' => self::SECRET,
            'format' => 'json'
        ]);

//        $req = new EleOfficialactivityGetRequest();//获取
        $req = new EleOrderGetRequest([
            'date_type'  => 4,//，1-付款时间 2-创建时间 3-结算时间 4-更新时间
            'biz_unit' => 2,
            'page_size' => 50,
            'page_number' => $page,
            'start_date' => Carbon::now()->subDays(2)->toDateTimeString(),
            'end_date' => Carbon::now()->toDateTimeString(),
        ]);

        $data =  $taobao->execute($req);

        $data = json_decode(json_encode($data), true);
        $data = $data['result'] ?? [];
        $data = $data['order_detail_report_d_t_o'] ?? [];
        $res['data'] = $data;
        return $res ?? [];
    }

}